import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/new_air_cooling_page/temperature_full_chart/component/full_screen_back.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'temperature_full_chart_controller.dart';

class TemperatureFullChartPage extends GetView<TemperatureFullChartController> {
  const TemperatureFullChartPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TemperatureFullChartController>(
        builder: (_) => SafeArea(
                child: RotatedBox(
              quarterTurns: 1,
              child: Scaffold(
                backgroundColor: Colors.white,
                body: Column(
                  children: [
                    // Gaps.vGap10,
                    FullScreenBack(() {
                      Log.d('back');
                      Get.back();
                    }),
                    Expanded(
                        child: Container(
                      color: Colors.white,
                      padding: EdgeInsets.only(left: 0, right: 0),
                      child: Echarts(
                        captureAllGestures: false,
                        option: '''
 {
  color: ['#3DD598', '#007DFF'],
 /// 纵轴
  yAxis: [
    {
      type: 'value',
      name: '${ResKey.temperature.tr}',
      // min:0,
      // max:800,
      nameTextStyle: {
        align: "left"
      },
      offset: 0,
      /// 坐标轴在 grid 区域中的横向分隔线
      splitLine: {
        show: true,
        lineStyle: {
          type: [10, 5],
          dashOffset: 5,
          color: 'rgba(0,0,0,0.09)',
          width: 1
        }
      },
      axisLabel: {
        color: '#999999',
        fontSize: 11,
      },
    }
  ],
     /// 横轴
  xAxis: {
    type: 'category',                
    axisLine:{
      show: false,
    }, 
    
    axisTick: {
      show: false
    }, 
    axisLabel: {
      color: '#999999',
      fontSize: 11,
      // interval: function (index) { // 自定义间隔函数 
      //     if (index % 4 === 0) { // 每四小时显示一次  // 返回值是五分钟为一个间隔
      //         return true;
      //     } else {
      //         return false;
      //     }
      // },
    },
  },
  dataZoom: [
    {
      type: 'inside',
      realtime: false,
    },
    {
      start: 0,
      end: 0,
      height: 10,
      bottom:55,
      realtime: false,
    },
  ],
  /// 坐标轴
  grid: {
    top: 30,
    bottom: 70,
    right: 20,
    left:30,
    containLabel: true,
  },
  
  legend: {
    show: true,
    icon: 'rect',
    itemHeight: 3,
    itemWidth: 12,
    bottom: 5,
    right: 20,
    left:30,
  },
  
  ///提示框
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.85)',
    borderWidth: 0,
    opacity: 0.2,
    confine: true,
    padding: [
      10, // 上
      8, // 右
      10, // 下
      8 // 左
    ],
    textStyle: {
      color: 'white'
    },
        axisPointer: {
      /// 坐标轴指示器配置项
      lineStyle: {
        color: 'rgba(0,0,0,0.09)',
        position: function (pt) {
          return [pt[0], 500];
        }
      }
    },
  },
    /// 图表数据
  series: [
    {
      name: '${ResKey.deviceGunTemp.tr}',
      color: '#1890FF',
      type: 'line',
      data: ${jsonEncode(controller.gunTemperatureData)},
    },
    {
      name:  '${ResKey.deviceSingleBatteryMaxtemp.tr}', //单体电池最高温度
      color: '#2FC25B',
      type: 'line',
     data: ${jsonEncode(controller.maxTemperatureData)},
    },
    {
      name: '${ResKey.deviceSingleBatteryMintemp.tr}', //单体电池最低温度
      color: '#67D7FC',
      type: 'line',
     data: ${jsonEncode(controller.minTemperatureData)},
    },
    {
      name:  '${ResKey.deviceChargeGunAnodetemp.tr}', //充电枪正极温度
      color: '#F79631',
      type: 'line',
     data: ${jsonEncode(controller.gunPositiveTemperatureData)},
    },
    {
      name: '${ResKey.deviceChargeGunCathodetemp.tr}', //充电枪负极温度
      color: '#FAC958',
      type: 'line',
      data: ${jsonEncode(controller.gunNegativeTemperatureData)},
    },
  ],
}
  ''',
                      ),
                    ))
                  ],
                ),
              ),
            )));
  }
}
